import QRCode from "qrcode";

const opts = {
    errorCorrectionLevel: "H",
    type: "image/jpeg",
    quality: 0.8,
    margin: 1,
    color: {
        dark: "#000",
        light: "#fff",
    },
};

export const useContent = () => {
    const dialogStore = useDialogStore();
    const QrCodeUrl = ref("");

    watchEffect(async () => {
        if (dialogStore.shareUrl) {
            const url = await QRCode.toDataURL(dialogStore.shareUrl, opts);
            QrCodeUrl.value = url;
        }
    });

    const onCopyUrl = () => {
        copy(dialogStore.shareUrl);
        Message().success("复制成功");
    };

    const onDownloadQrCode = () => {
        download(QrCodeUrl.value, dialogStore.shareName + "二维码.jpg");
    };

    return {
        dialogStore,
        QrCodeUrl,
        onCopyUrl,
        onDownloadQrCode,
    };
};
